import request from "@/utils/request";
import { RoleInfoResponseType, UserAddInfoType, UserPagingType } from "./types";

/**
 * 请求获取用户分页列表
 * @param page
 * @param limit
 * @param data
 * @returns
 */
export const reqGetUserList = (
  page: number,
  limit: number,
  username: string
) => {
  return request.get<null, UserPagingType>(
    `/admin/acl/user/${page}/${limit}?username=${username}`
  );
};

/**
 * 请求添加用户
 * @param role 用户信息
 * @returns
 */
export const reqAddUserInfo = (userInfo: UserAddInfoType) => {
  return request.post(`/admin/acl/user/save`, userInfo);
};

/**
 * 请求修改用户
 * @param role 用户信息
 * @returns
 */
export const reqUpdateUserInfo = (userInfo: UserAddInfoType) => {
  return request.put(`/admin/acl/user/update`, userInfo);
};

/**
 * 请求删除用户
 * @param id 用户id
 * @returns
 */
export const reqDelUserInfo = (id: string) => {
  return request.put(`/admin/acl/user/remove/${id}`);
};

/**
 * 请求根据用户id获取角色
 */
export const reqGetRoleInfo = (adminId: number) => {
  return request.get<null, RoleInfoResponseType>(
    `/admin/acl/user/toAssign/${adminId}`
  );
};

/**
 * 请求分配角色
 */
export const reqSetRole = (adminId: number, roleId: number[]) => {
  return request.post(
    `/admin/acl/user/doAssign?adminId=${adminId}&roleId=${roleId}`
  );
};
